/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package data;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
//import javax.sql.DataSource;

/**
 *
 * @author bertram
 */
public class PostGres {
    DataSource ds;
    private static PostGres instance = null;
    private PostGres()
    {
        try{
            Context initCtx = new InitialContext();
            Context envCtx = (Context) initCtx.lookup("java:comp/env");
            ds = (DataSource) envCtx.lookup("jdbc/ImgDB");

        }
        catch(Exception ex){
            System.out.println("fejl: " + ex.getMessage());
        }
    }
    public static PostGres getInstance()
    {
        if(instance == null) instance = new PostGres();
        return instance;
    }

    public synchronized Connection getConnection() throws SQLException
    {
        return ds.getConnection();
    }

   

}
